#include "codec.h"
#include "fsl_iomuxc.h"
#include "fsl_gpio.h"
#include "appCommon.h"

#define CODEC_RESET_PIN_ID        IOMUXC_GPIO_AD_B1_08_GPIO1_IO24
#define CODEC_RESET_PIN_PORT      GPIO1
#define CODEC_RESET_PIN_NUM       24u


void codecInit(void)
{
	gpio_pin_config_t pinConfig={kGPIO_DigitalOutput,0,kGPIO_NoIntmode};
	IOMUXC_SetPinMux(CODEC_RESET_PIN_ID,0);
	IOMUXC_SetPinConfig(CODEC_RESET_PIN_ID, PIN_CONFIG_OUTPUT);
	GPIO_PinInit(CODEC_RESET_PIN_PORT, CODEC_RESET_PIN_NUM, &pinConfig);
    //codecReset();
}


void codecReset(void)
{
    CODEC_RESET_PIN_PORT->DR_CLEAR = 1ul << CODEC_RESET_PIN_NUM;
    SDK_DelayAtLeastUs(100000, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
    CODEC_RESET_PIN_PORT->DR_SET = 1ul << CODEC_RESET_PIN_NUM;
    SDK_DelayAtLeastUs(100000, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);    
}

void codecResetFree(void)
{
    CODEC_RESET_PIN_PORT->DR_SET = 1ul << CODEC_RESET_PIN_NUM;
}